package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.mainCategory.MainCategoryDto;
import com.java110.intf.goods.IMainCategoryInnerServiceSMO;
import com.java110.mall.goods.dao.IMainCategoryServiceDao;
import com.java110.po.mainCategory.MainCategoryPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 主目录内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class MainCategoryInnerServiceSMOImpl extends BaseServiceSMO implements IMainCategoryInnerServiceSMO {

    @Autowired
    private IMainCategoryServiceDao mainCategoryServiceDaoImpl;


    @Override
    public int saveMainCategory(@RequestBody MainCategoryPo mainCategoryPo) {
        int saveFlag = 1;
        mainCategoryServiceDaoImpl.saveMainCategoryInfo(BeanConvertUtil.beanCovertMap(mainCategoryPo));
        return saveFlag;
    }

    @Override
    public int updateMainCategory(@RequestBody MainCategoryPo mainCategoryPo) {
        int saveFlag = 1;
        mainCategoryServiceDaoImpl.updateMainCategoryInfo(BeanConvertUtil.beanCovertMap(mainCategoryPo));
        return saveFlag;
    }

    @Override
    public int deleteMainCategory(@RequestBody MainCategoryPo mainCategoryPo) {
        int saveFlag = 1;
        mainCategoryPo.setStatusCd("1");
        mainCategoryServiceDaoImpl.updateMainCategoryInfo(BeanConvertUtil.beanCovertMap(mainCategoryPo));
        return saveFlag;
    }

    @Override
    public List<MainCategoryDto> queryMainCategorys(@RequestBody MainCategoryDto mainCategoryDto) {

        //校验是否传了 分页信息

        int page = mainCategoryDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            mainCategoryDto.setPage((page - 1) * mainCategoryDto.getRow());
        }

        List<MainCategoryDto> mainCategorys = BeanConvertUtil.covertBeanList(mainCategoryServiceDaoImpl.getMainCategoryInfo(BeanConvertUtil.beanCovertMap(mainCategoryDto)), MainCategoryDto.class);

        return mainCategorys;
    }


    @Override
    public int queryMainCategorysCount(@RequestBody MainCategoryDto mainCategoryDto) {
        return mainCategoryServiceDaoImpl.queryMainCategorysCount(BeanConvertUtil.beanCovertMap(mainCategoryDto));
    }

    public IMainCategoryServiceDao getMainCategoryServiceDaoImpl() {
        return mainCategoryServiceDaoImpl;
    }

    public void setMainCategoryServiceDaoImpl(IMainCategoryServiceDao mainCategoryServiceDaoImpl) {
        this.mainCategoryServiceDaoImpl = mainCategoryServiceDaoImpl;
    }
}
